package com.yanqu.road.server.cmd.beautyescort;

import com.yanqu.road.pb.beautyescort.BeautyEscortProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.beautyescort.CrossBeautyEscortRankMgr;
import com.yanqu.road.server.manager.beautyescort.CrossGroupWeekUnionRankListModel;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.C_BEAUTY_ESCORT_GET_UNION_RANK_REWARD, desc = "领取商会排行奖励")
public class CrossBeautyEscortGetUnionRankRewardCmd extends CrossCommand {

    int weekId;
    String unionUid;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BeautyEscortProto.CrossBeautyEscortGetUnionRankRewardReqMsg reqMsg = BeautyEscortProto.CrossBeautyEscortGetUnionRankRewardReqMsg.parseFrom(packet.getBytes());
        weekId = reqMsg.getWeekId();
        unionUid = reqMsg.getUnionUid();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        BeautyEscortProto.BeautyEscortGetUnionRankRewardRespMsg.Builder respMsg = BeautyEscortProto.BeautyEscortGetUnionRankRewardRespMsg.newBuilder();
        respMsg.setRank(-1);
        int groupId = CrossBeautyEscortRankMgr.getWeekServerGroup(weekId, serverId);
        CrossGroupWeekUnionRankListModel rankListModel = CrossBeautyEscortRankMgr.getCrossGroupWeekUnionRankListModel(weekId, groupId);
        if(rankListModel != null){
            respMsg.setRank(rankListModel.getMyRank(unionUid));
        }
        respMsg.setGroupId(groupId);
        respMsg.setRet(0);
        respMsg.setWeekId(weekId);
        MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.S_BEAUTY_ESCORT_GET_UNION_RANK_REWARD_FROM_CROSS, respMsg));
    }

    @Override
    public void sendData() {

    }
}
